// 静态路由配置
// 书写格式与动态路由格式一致，全部经由框架统一转换
// 比较动态路由在meta中多加入了role角色权限，为数组类型。一个菜单是否有权限显示，取决于它以及后代菜单是否有权限。
// routes 显示在左侧菜单中的路由(显示顺序在动态路由之前)
// import http from "@/utils/request"

import tool from '@/utils/tool';

const routes = [
    {
        name: "home",
        path: "/home",
        meta: {
            title: "首页",
            icon: "fe-airplay",
            type: "menu",
            moveable: false, //是否展示上下移动按钮
        },
        children: [{
            name: "dashboard",
            path: "/dashboard",
            meta: {
                title: "系统首页",
                icon: "el-icon-menu",
                affix: true,
                moveable: false, //是否展示上下移动按钮
                params: {id: 1} //传递参数,在页面中用 this.$route.meta.params 接收
            },
            component: "home"
        }]
    },
    {
        name: "record",
        path: "/record",
        meta: {
            title: "记录",
            icon: "fe-bar-chart-line",
            type: "menu"
        },
        children: [
            {
                path: "/record/learn",
                name: "record-learn",
                meta: {
                    title: "上课记录",
                    icon: "fe-align-justify",
                    type: "menu"
                },
                component: "learn"
            },
            {
                path: "/record/exam",
                name: "record-exam",
                meta: {
                    title: "测试记录",
                    icon: "fe-align-justify",
                    type: "menu"
                },
                component: "vocabularyExam"
            },
            {
                path: "/record/article",
                name: "record-article",
                meta: {
                    title: "阅读理解",
                    icon: "fe-align-justify",
                    type: "menu",
                },
                component: "articleExercise"
            },
            {
                path: "/record/recharge",
                name: "record-recharge",
                meta: {
                    title: "课时记录",
                    icon: "fe-align-justify",
                    type: "menu"
                },
                component: "classHour/log"
            },
            {
				path: "/finance/log",
				name: "finance-log",
				meta: {
					title: "佣金记录",
					icon: "mdi mdi-playlist-check",
					type: "menu",
					role: ['record-finance-view']
				},
				component: "finance/log"
			},
        ]
    },
    {
        name: "user",
        path: "/user",
        meta: {
            title: "用户",
            icon: "fe-user",
            type: "menu"
        },
        children: [
            {
                path: "/user/list",
                name: "user-list",
                meta: {
                    title: "学员管理",
                    icon: "fe-users",
                    type: "menu"
                },
                component: "user"
            },
        ]
    },
    {
        name: "agent",
        path: "/agent",
        meta: {
            title: "机构",
            icon: "fe-user",
            type: "menu"
        },
        children: [
            {
                path: "/agent/list",
                name: "agent-list",
                meta: {
                    title: "机构列表",
                    icon: "fe-users",
                    type: "menu"
                },
                component: "agent"
            },
            {
                path: "/agent/audit/list",
                name: "agent-audit-list",
                meta: {
                    title: "开户申请",
                    icon: "fe-minimize",
                    type: "menu"
                },
                component: "agent/agentAudit"
            },
            {
                path: "/agent/parnter/audit",
                name: "agent-parnter-audit",
                meta: {
                    title: "合伙人名额申请",
                    icon: "fe-compass",
                    type: "menu"
                },
                component: "agent/parnterAudit"
            },
        ]
    },
    {
        name: "teacher",
        path: "/teacher",
        meta: {
            title: "教练",
            icon: "fe-user",
            type: "menu"
        },
        children: [
            {
                path: "/teacher/list",
                name: "teacher-list",
                meta: {
                    title: "教练列表",
                    icon: "fe-users",
                    type: "menu"
                },
                component: "teacher"
            },
            {
                path: "/teacher/audit/list",
                name: "teacher-audit-list",
                meta: {
                    title: "教练审核",
                    icon: "fe-check-circle",
                    type: "menu"
                },
                component: "teacherAudit"
            },
        ]
    },
    {
        name: "course",
        path: "/course",
        meta: {
            title: "教学",
            icon: "el-icon-document",
            type: "menu"
        },
        children: [
            {
                path: "/course/list",
                name: "course-list",
                meta: {
                    title: "课程管理",
                    icon: "mdi mdi-bullseye",
                    type: "menu"
                },
                component: "course"
            }
        ]
    },
    {
        name: "salary",
        path: "/salary",
        meta: {
            title: "薪资",
            icon: "fe-pocket",
            type: "menu"
        },
        children: [
            {
                path: "/salary/config/list",
                name: "salary-config-list",
                meta: {
                    title: "薪资设置",
                    icon: "fe-settings",
                    type: "menu"
                },
                component: "salary/config"
            },
            {
                path: "/salary/teacher/calculate",
                name: "salary-teacher-calculate",
                meta: {
                    title: "薪资计算",
                    icon: "fe-dollar-sign",
                    type: "menu"
                },
                component: "salary/calculate"
            },
        ]
    },
    {
        name: "setting",
        path: "/setting",
        meta: {
            title: "配置",
            icon: "el-icon-setting",
            type: "menu"
        },
        children: [
        {
            path: "/setting/message",
            name: "setting-message",
            meta: {
                title: "消息通知",
                icon: "el-icon-chat-square",
                type: "menu"
            },
            component: "message"
        }]
    }
]

var _remoteRoute = []
export async function remoteRoute(reset = false) {

    if (_remoteRoute.length > 0 && ! reset) {
        return _remoteRoute
    }

    let userInfo = tool.data.get("G_USER_INFO");
    routes.forEach((ele, index) => {
        
        if (userInfo.level && userInfo.level.id != 11) {
            if (ele.name == 'agent') {
                ele.children.forEach((item, index) => {
                    if (item.path == '/agent/parnter/audit') {
                        ele.children.splice(index, 1)
                    }
                })
            }
        }else {
            if (ele.name == 'agent') {
                const _children = [
                    {
                        path: "/agent/list",
                        name: "agent-list",
                        meta: {
                            title: "机构列表",
                            icon: "fe-users",
                            type: "menu"
                        },
                        component: "agent"
                    },
                    {
                        path: "/agent/audit/list",
                        name: "agent-audit-list",
                        meta: {
                            title: "开户申请",
                            icon: "fe-minimize",
                            type: "menu"
                        },
                        component: "agent/agentAudit"
                    },
                    {
                        path: "/agent/parnter/audit",
                        name: "agent-parnter-audit",
                        meta: {
                            title: "合伙人名额申请",
                            icon: "fe-compass",
                            type: "menu"
                        },
                        component: "agent/parnterAudit"
                    },
                ]
                ele.children = _children
            }
        }
    })

    return routes;
}

export {
    routes,
};
